<?php
Class DiscussAction extends Action{
	public function user(){
		$user['id'] =$this->userid = intval(I('id'));
		$this->user = $user = M('User')->where($user)->find();//当前用户的一些基本信息

		$condition['user_id']=$user['id'];

		($filter = I('filter'))?($this->filter = $filter):($this->filter = $filter = 1);
		switch ($filter) {
			case '1':
				$condition['cashtype']=1;
				$condition['pubtype']=array('neq',3);
				break;
			case '2':
				$condition['cashtype']=array('gt',1);
				break;
			case '3':
				$condition['pubtype']=3;
				break;
		}

		import('ORG.Util.EditPage');
		$count = M('MedicalRecordsDiscuss')->where($condition)->count();
		$Page = new Page($count,10);
        $Page->setConfig('theme',"<ul class='pagination'><li><a>%totalRow% %header% %nowPage%/%totalPage% 页</a></li><li>%upPage%</li><li>%first%</li><li>%prePage%</li><li>%linkPage%</li><li>%nextPage%</li><li>%end%</li><li>%downPage%</li>".$gopagenu."</ul>");
		$this->page = $Page->show();
        $this->discuss =  M('MedicalRecordsDiscuss')->where($condition)->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->currentpage = $Page->firstRow + 1; 	
        $this->display();
	}

	public function getcontent(){
		$condition['id']=I('id');
		$data = M('MedicalRecordsDiscuss')->where($condition)->find();
		$this->ajaxReturn($data,"JSON");
	}

	public function postcontent(){
		$condition['id']=I('id');
		$data['content']=I('content');
		$save = M('MedicalRecordsDiscuss')->where($condition)->save($data);
		if($save!==false){
			$this->ajaxReturn(array("status"=>1),"JSON");
		}else{
			$this->ajaxReturn(array("status"=>0),"JSON");
		}
	}
}